package com.beifu.manager.service.assetscrapdetail.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beifu.manager.api.domain.scrap.ScrapProduct;
import com.beifu.manager.dao.AssetScrapDetailMapper;
import com.beifu.manager.dao.AssetScrapMapper;
import com.beifu.manager.model.AssetScrapDetail;
import com.beifu.manager.model.AssetScrapDetailExample;
import com.beifu.manager.service.assetscrapdetail.AssetScrapDetailService;
@Service
public class AssetScrapDetailServiceImpl implements AssetScrapDetailService {
	@Autowired
	private AssetScrapDetailMapper assetScrapDetailMapper;
	@Autowired
	private AssetScrapMapper assetScrapMapper;
	@Override
	public String getScrapNum(int assetScrapId, String status) {
		// status：1 报废;2 驳回;0 未处理
		AssetScrapDetailExample example = new AssetScrapDetailExample();
		example.createCriteria().andAssetScrapIdEqualTo(assetScrapId).andScrapStatusEqualTo(1);
		int scrapNum = assetScrapDetailMapper.countByExample(example);
		return scrapNum+"";
	}
	
	@Override
	public List<ScrapProduct> getAssetScrapDetail(int assetScrapId, String status) {
		List<ScrapProduct> list = new ArrayList<ScrapProduct>();
		// 通过报废单id获取报废资产列表
		AssetScrapDetailExample example = new AssetScrapDetailExample();
		example.createCriteria().andAssetScrapIdEqualTo(assetScrapId);
		List<AssetScrapDetail> detailList = assetScrapDetailMapper.selectByExample(example);
		if(null != detailList && detailList.size() > 0){
			for (AssetScrapDetail assetScrapDetail : detailList) {
				String rfidCode = assetScrapDetail.getAssetInfoRfidCode();
				Map<String, Object> assetType = assetScrapDetailMapper.getTypeName(rfidCode);//获取资产名称和自定义编号

				ScrapProduct sp = new ScrapProduct();
				sp.setRFID(rfidCode);
				sp.setStatus(assetScrapDetail.getScrapStatus().toString());
				if(null != assetType){
					sp.setTypeName((String) assetType.get("typeName"));
					sp.setTypeId((String) assetType.get("typeId"));
				}
				list.add(sp);
			}
		}
		
		return list;
	}

}
